package com.atguigu.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author ：MJS
 * @date ：Created in 2021/4/25  20:45
 * @description：TODO
 */
public class CallableDemo {
    //FutureTask
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask(new MyThread());
        Thread thread = new Thread(futureTask,"张三");
        thread.start();
        System.out.println(Thread.currentThread().getName()+"\t"+"--end");
        System.out.println(futureTask.get());//一般这个get方法，最好放在最后,否则有可能形成阻塞


    }
}


class MyThread implements Callable<String>{
    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName() + "\t haha");
        Thread.sleep(3000);
        return "hello java";
    }
}
